// 云函数入口文件 index.js

const cloud = require('wx-server-sdk')
cloud.init({ env: 'poems-7g8s3plt3e724965' }) // 使用当前云环境
const db = cloud.database()

exports.main = async (event, context) => {
  try {
    const feedbackContent = event.content
    // console.log('反馈内容:', feedbackContent) 
    const timestamp = new Date().getTime()

    // 向 get_feedback 集合添加一条反馈数据
    const res = await db.collection('get_feedback').add({
      data: {
        content: feedbackContent,
        timestamp: timestamp
      }
    })
    // console.log('写入数据库成功:', res)
    return res
  } catch (err) {
    return err
  }
}
